class ContentPieceFactory
{
    private static s_ContentPieceFactory:ContentPieceFactory;
    public static getInstance():ContentPieceFactory
    {
        if(this.s_ContentPieceFactory == null)
        {
            this.s_ContentPieceFactory = new ContentPieceFactory();
        }
        return this.s_ContentPieceFactory;
    }
    private m_ContentPieceArray:Array<ContentPiece>;
    private constructor()
    {
        this.m_ContentPieceArray = new Array<ContentPiece>();
    }
    public GetContentPieceLength()
    {
        return this.m_ContentPieceArray.length;
    }
    public Reset()
    {
        for(let i = 0; i < this.m_ContentPieceArray.length; i++)
        {
            this.m_ContentPieceArray[i].setDisable();
            this.m_ContentPieceArray[i].m_isAdd = false;
        }
    }
    public CreateContentPiece(key:string,pic:string, speed:number, addTag:number):ContentPiece
    {
        let contentPiece:ContentPiece;
        for(let i = 0; i < this.m_ContentPieceArray.length; i++)
        {
            if(this.m_ContentPieceArray[i].getId() == key && !this.m_ContentPieceArray[i].getActivity() && this.m_ContentPieceArray[i].m_addTag == addTag)
            {
                contentPiece = this.m_ContentPieceArray[i];
                contentPiece.resetInfo(pic,speed);
                break;
            }
        }
        if(contentPiece == null)
        {
            contentPiece = this.CreateContentPieceByKey(key,pic,speed,addTag);
            this.m_ContentPieceArray.push(contentPiece);
        }
        return contentPiece;
    }
    private CreateContentPieceByKey(key:string,pic:string,speed:number,addTag:number):ContentPiece
    {
        let contentPiece:ContentPiece = new ContentPiece(key,pic,speed,addTag);
        return contentPiece;
    }
}